//
//  ByItemCell.m
//  jmsfhz_ios
//
//  Created by pro on 16/7/19.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "ByItemCell.h"

@implementation ByItemCell

+ (instancetype)createCellInTableview:(UITableView *)table {
    
    static NSString *cellIdentifier = @"ByItemCell";
    ByItemCell *cell = [table dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[self alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style
              reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSeparatorStyleNone;
        self.backgroundColor = [UIColor whiteColor];
        [self initSubviews];
    }
    return self;
}

- (void)initSubviews {
    
    CGFloat x, y, width, height;

    
    /** 项目  Label */
    x = 10;
    y = 10;
    width = SCREEN_WIDTH - 2 * x;
    height = 15;
    self.itemLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
    self.itemLabel.textColor = [UIColor blackColor];
    self.itemLabel.font = FONT(14);
    self.itemLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:self.itemLabel];
    self.itemLabel.text = @"杭州空用机场跑道土方运输项目";
    
    /** 来源 */
    x = 10;
    y = self.itemLabel.bottom + 10;
    width = 0;
    height = 15;
    self.fromLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
    self.fromLabel.textColor = [UIColor lightGrayColor];
    self.fromLabel.font = FONT(12);
    self.fromLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:self.fromLabel];
    self.fromLabel.text = @"来源：浙江经贸";

    self.fromLabel.width = [self.fromLabel.text getSizeOfString:12].width;
    
    /** 时间 */
    x = self.fromLabel.right + 30;
    y = self.fromLabel.top;
    width = 0;
    height = 15;
    self.dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
    self.dateLabel.textColor = [UIColor lightGrayColor];
    self.dateLabel.font = FONT(12);
    self.dateLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:self.dateLabel];
    self.dateLabel.text = @"发布时间：2016-7-7";
    
    self.dateLabel.width = [self.dateLabel.text getSizeOfString:12].width;
    
    /** 内容 */
    x = 10;
    y = self.fromLabel.bottom + 10;
    width = SCREEN_WIDTH - 2 * x;
    height = 30;
    self.contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, y, width, height)];
    self.contentLabel.textColor = [UIColor grayColor];
    self.contentLabel.numberOfLines = 2;
    self.contentLabel.font = FONT(12);
    self.contentLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:self.contentLabel];
    self.contentLabel.text = @"他正在寻找合伙人共同完成项目，需要合伙人提供资金支持，可做到帮约见业主可做到帮约见业主可做到帮约见业主";
}


- (void)setModel:(ByNetItemResultItemModel *)model {
    _model = model;
    
    /** 项目标题 */
    self.itemLabel.text = _model.title;
    
    /** 项目来源 */
    self.fromLabel.text = [NSString stringWithFormat:@"来源：%@", _model.come_from];
//    self.fromLabel.width = [self.fromLabel.text getSizeOfString:12].width;
    self.fromLabel.width = self.dateLabel.left - 5 - self.fromLabel.left;

    /** 发布时间 */
    NSString *createTime = [NSDate getDateForStringFotmatWithTimeInterval:_model.create_time.doubleValue formatter:@"yyyy-MM-dd"];
    self.dateLabel.text = [NSString stringWithFormat:@"发布时间：%@", createTime];
    self.dateLabel.width = [self.dateLabel.text getSizeOfString:12].width;

    /** 内容 */
    self.contentLabel.text = _model.summary;
}

@end
